package LockSupport与线程中断.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2022-08-12 07:26
 **/
public class InterruptDemo2 {
    public static void main(String[] args) {
        final Thread t1 = new Thread(() -> {
            for (int i = 0; i < 300; i++) {
                System.out.println("--------" + i);
            }
            System.out.println("t1线程调用interrupt()方法后的中断标志02：" + Thread.currentThread().isInterrupted());
        }, "t1");
        t1.start();
        System.out.println("t1线程的默认中断标志：" + t1.isInterrupted());
        try {
            TimeUnit.MILLISECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t1.interrupt();
        System.out.println("t1线程调用interrupt()方法后的中断标志01：" + t1.isInterrupted());

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("t1线程调用interrupt()方法后的中断标志03：" + t1.isInterrupted());

    }
}
